package com.zlm.custom.proxy;

import org.springframework.transaction.annotation.Transactional;

import java.sql.Connection;
import java.sql.SQLException;

import static java.sql.DriverManager.getConnection;

/**
 * @author zlm
 * @date 2025/4/22
 */
interface MyService{

    void insertOne() throws SQLException;
}
public class MyServiceImpl implements MyService{

    @Transactional(rollbackFor=RuntimeException.class)
    public void insertOne() {
        System.out.println("insert one");
    }
}

class MyService$Proxy1 implements MyService{
    private MyService myService;


    @Override
    public void insertOne() throws SQLException {
        Connection connection = getConnection();
        try {
            connection.setAutoCommit(false);
            myService.insertOne();
            connection.commit();
        } catch (RuntimeException e) {
            connection.rollback();
        }
    }

    private Connection getConnection() {
        return null;
    }
}

